﻿using QFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity.VisualScripting;
using UnityEngine;

namespace ProjectSurvivor
{
    public class ExpUpgradeSystem : AbstractSystem
    {

        public static EasyEvent OnCoinUpgradeSystemChanged = new EasyEvent();


        public List<ExpUpgradeItem> Items = new List<ExpUpgradeItem>();


        public ExpUpgradeItem Add(ExpUpgradeItem item)
        {
            Items.Add(item);
            return item;
        }

        protected override void OnInit()
        {
            ResetData();
            Global.Level.Register(_ =>
            {
                Roll();
            });
        }


        public void ResetData()
        {
            Items.Clear();  

            Add(new ExpUpgradeItem()
                .WithKey("simple_sword")
                .WithDescription(lv =>
                {
                    return lv switch
                    {
                        1=>$"剑LV{lv}:攻击身边的敌人",
                        2=>$"剑LV{lv}:\n攻击力+3 数量+2",
                        3=>$"剑LV{lv}:\n攻击力+2 间隔-0.25s",
                        4=>$"剑LV{lv}:\n攻击力+2 间隔-0.25s",
                        5=>$"剑LV{lv}:\n攻击力+3 数量+2",
                        6=>$"剑LV{lv}:\n范围+1 间隔-0.25s",
                        7=>$"剑LV{lv}:\n攻击力+3 数量+2",
                        8=>$"剑LV{lv}:\n攻击力+2 范围+1",
                        9=>$"剑LV{lv}:\n攻击力+3 间隔-0.25s",
                        10=>$"剑LV{lv}:\n攻击力+3 数量+2",
                        _=>null,
                    };
                })
                .WithMaxLevel(10)
                .OnUpgrade((_, level) =>
                {
                    switch(level)
                    {
                        case 1:
                            break;
                            case 2:
                            Global.SimpleAbilityDamage.Value += 3;
                            Global.SimpleSwordCount.Value += 2;
                            break;
                            case 3:
                            Global.SimpleAbilityDamage.Value += 2;
                            Global.SimpleAbilityDuration.Value -=0.25f;
                            break;
                        case 4:
                            Global.SimpleAbilityDamage.Value += 2;
                            Global.SimpleAbilityDuration.Value -= 0.25f;
                            break;
                            case 5:
                            Global.SimpleAbilityDamage.Value += 3;
                            Global.SimpleSwordCount.Value += 2;
                            break;
                            case 6:
                            Global.SimpleSwordRange.Value++;
                            Global.SimpleAbilityDuration.Value -= 0.25f;
                            break;
                        case 7:
                            Global.SimpleAbilityDamage.Value += 3;
                            Global.SimpleSwordCount.Value += 2;
                            break;
                        case 8:
                            Global.SimpleAbilityDamage.Value += 2;
                            Global.SimpleSwordRange.Value++;
                            break;
                        case 9:
                            Global.SimpleAbilityDamage.Value += 3;
                            Global.SimpleAbilityDuration.Value -= 0.25f;
                            break;
                        case 10:
                            Global.SimpleAbilityDamage.Value += 3;
                            Global.SimpleSwordRange.Value+=2;
                            break;

                    }
                })
                );

        }

        public void Roll()
        {
            foreach (var expUpgradeItem in Items)
            {
                expUpgradeItem.Visible.Value = false;
            }

            var item=  Items.Where(item => !item.UpgradeFinish).ToList().GetRandomItem();
            if(item == null)
            {

            }
            else
            {
            item.Visible.Value = true;
            }
        }
    }
}
